package com.zsrt.java.day20170112.lh.daily.ch06;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import org.junit.Test;

public class InputStreamReaderTest {
	
	public static void main(String[] args) {
		
		InputStream in = null;

		InputStreamReader isr = null;
		
		try {
			File f = new File("C:/A.txt");
			try {
				in = new FileInputStream(f);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			isr = new InputStreamReader(in);
			char[] b = new char[3];
			int len = 0;
			try {
				while ((len = isr.read(b)) != -1) {
					String st = new String(b, 0, len);
					System.out.print(st);

				}
			} catch (IOException e) {
				e.printStackTrace();
			} 
		} finally {
			if(null !=null){
				
				try {
					isr.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(null!=in){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				
			}
			
		}
		
	}
	
	
	@Test
	public void OutputStreamWriterTest() throws Exception {
		
		File f=new File("C:/A.txt");
		
		
		OutputStream out=new FileOutputStream(f);
		
		OutputStreamWriter osw=new OutputStreamWriter(out);
		
		String st="考试的骄傲大家罚款案件发卡机看电视剧啊";
		
		osw.write(st, 0, st.length());
		
		osw.close();
				
		
		
		
	}

}
